package cn.freeprogrammer.igen.generator;

import cn.freeprogrammer.igen.data.ProjectData;

/**
 * 组合其它生成器提供代码生成服务.
 * 
 * @see DaoGenerator
 * @see EntityGenerator
 * @see SqlMapConfigGenerator
 * @see SqlMapGenerator
 * 
 * @author minwh
 *
 */
public class FreeGenerator implements IGenerator {
	private ProjectData projectData;
	private SqlMapConfigGenerator sqlMapConfigGenerator;
	private SqlMapGenerator sqlMapGenerator;
	private EntityGenerator entityGenerator;
	private DaoGenerator daoGenerator;
	
	public FreeGenerator(String configFile) throws Exception {
		System.out.print("Loading config...");
		projectData = ProjectData.newInstance(configFile);
		sqlMapConfigGenerator = new SqlMapConfigGenerator(projectData);
		sqlMapGenerator = new SqlMapGenerator(projectData);
		entityGenerator = new EntityGenerator(projectData);
		daoGenerator = new DaoGenerator(projectData);
		System.out.println("finish.");
	}
	
	public void generate() throws Exception {
		System.out.print("Generate the files...");
		sqlMapConfigGenerator.generate();
		sqlMapGenerator.generate();
		entityGenerator.generate();
		daoGenerator.generate();
		System.out.println("finish.");
	}
}
